<?php

/**
 * Base project form.
 * 
 * @package    maximous
 * @subpackage form
 * @author     Your name here 
 * @version    SVN: $Id: BaseForm.class.php 20147 2009-07-13 11:46:57Z FabianLange $
 */
class BaseForm extends sfFormSymfony
{

    /**
     * set formatter for the form
     * @author Micheal Mouner
     * @param String $formatterName 
     */
    public function addFormatter($formatterName)
    {
        $customDecorator = new sfWidgetFormSchemaCustomFormatter($this->getWidgetSchema());
        $this->widgetSchema->addFormFormatter($formatterName, $customDecorator);
        $this->widgetSchema->setFormFormatterName($formatterName);
        $this->addRequiredSpan();
    }
    
    public function addRequiredSpan(array $ignoreArray = array())
    {
        $Validatorfileds = $this->getValidatorSchema()->getFields();
        $requiredArray = array();
        foreach($Validatorfileds as $name => $validator)
        {
            if($validator->getOption("required") && array_search($name, $ignoreArray) === false )
            {
                $requiredArray[] = $name;
            }
        }
        $this->getWidgetSchema()->getFormFormatter()->setRequiredFields($requiredArray);
    }

}
